package com.ada.tft_sport.fragment;

import android.content.ServiceConnection;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.ada.mcu.service.IContactUi;
import com.ada.mcu.service.MachineData;
import com.ada.mcu.service.ServiceRepliedData;
import com.ada.tft_sport.MainActivity;
import com.ada.tft_sport.R;
import com.ada.tft_sport.utils.SharedPreferencesUtils;

public class StopSportFragment extends Fragment{
	
	MainActivity mainActivity = (MainActivity)getActivity();
	
	private View ssFragment; // 休息界面

	private FragmentManager fManager; // 碎片管理器
	private FragmentTransaction fTransaction; // 获取事务处理对象
	
	private TextView stop_clean;  //  
	private TextView average_calorie; // 卡路里/小时
	private TextView training_incline; // 平均坡度
	private TextView training_pace;  // 平均步伐
	private TextView training_speed;  // 平均速度
	private TextView training_distance; // 行走的距离
	private TextView training_time; // 训练时长
	private TextView training_consume_calories; // 消耗的卡路里
	
	public ServiceRepliedData data_rest;
	public IContactUi mService;
	private ServiceConnection mConnection;
	public static MachineData mMachineData = null;
	
	String fitness_time;
	String fitness_distance;
	String fitness_calorie;
	TextView pop_calorie ;    
	PopupWindow pop;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		// 每次切换此页面时，不需要重新创建Fragment对象
		setRetainInstance(true);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

		// 实例化布局文件
		ssFragment = inflater.inflate(R.layout.fragment_stop_sport, container,
				false);

		fManager = getActivity().getSupportFragmentManager(); 	// 获得碎片管理器
		fTransaction = fManager.beginTransaction(); 			// 获取事务处理对象
		pop_calorie= (TextView) getActivity().findViewById(R.id.test_tv);
//		pop=getActivity().
	
		fitness_time=SharedPreferencesUtils.getString(getActivity(), "fitness_timeInfo", "fitness_time");
	    fitness_distance=SharedPreferencesUtils.getString(getActivity(), "fitness_distanceInfo", "fitness_distance");
		fitness_calorie=SharedPreferencesUtils.getString(getActivity(), "fitness_calorieInfo", "fitness_calorie");
//		pop_calorie.getText();		
//		data_rest = mainActivity.data;
//		data_rest.getCalories();
//		Log.i("data_rest.getCalories()", "88888"+data_rest.getCalories());
//		pop_calorie=(TextView)pop.findViewById(R.id.pop_calorie);
		
		initShowTextView();
		initdata();
		
		
		return ssFragment; // 返回视图对象
		
	}

		

	private void initdata() {
		// TODO Auto-generated method stub
		if (mMachineData == null)			
		mMachineData = MachineData.getInstance();
		training_time.setText(fitness_time + "  " + getResources().getString(R.string.m_s));
		training_distance.setText(fitness_distance+"  "+getResources().getString(R.string.kolimeter));
		training_consume_calories.setText(fitness_calorie+"  "+getResources().getString(R.string.kilocalorie));
	}

	
	private void initShowTextView() {
		// TODO Auto-generated method stub
		training_consume_calories=(TextView)ssFragment.findViewById(R.id.training_consume_calories);
		training_time=(TextView)ssFragment.findViewById(R.id.training_time);
		training_distance=(TextView)ssFragment.findViewById(R.id.training_distance);
		training_speed=(TextView)ssFragment.findViewById(R.id.training_speed);
		training_pace=(TextView)ssFragment.findViewById(R.id.training_pace);
		training_incline=(TextView)ssFragment.findViewById(R.id.training_incline);
		average_calorie=(TextView)ssFragment.findViewById(R.id.average_calorie);
		stop_clean=(TextView)ssFragment.findViewById(R.id.stop_clean);
		
	}

}
